home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0063_Latitude-Longitude.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-09  |  1KB  |  42 lines

  1. {
  2.    Any navigators out there?  I need formulas or source code to calculate
  3.    the distance between two points given the latitude and longitude
  4.    of each point.  I'm trying to write some support software for my
  5.    Sony Pyxis GPS (global positioning system). }
  6.  
  7.  
  8.  Procedure Dist( Var xlat1,xlon1,xlat2,xlon2,xdist,ydist,distance : Real);
  9.  {
  10.  Returns the distance ( in km ) between two points on a tangent plane
  11.  on the earth.
  12.  }
  13.   Const
  14.    Km = 111.19;
  15.    C1 = 0.017453292;
  16.   Var
  17.    Xmlat,
  18.    cosm,
  19.    Adist   : Real;
  20.  
  21.   Begin { Dist }
  22.  { Calculate cos of mean latitude }
  23.    Xmlat := (xlat1+xlat2)/2;
  24.    cosm  := cos(xmlat*C1);
  25.  { Calculate Y (N-S) distance }
  26.    ydist := (xlat2-xlat1)*km;
  27.  { Calculate X (E-W) distance }
  28.    xdist := (xlon2-xlon1)*km*cosm;
  29.  { Calculate total distance }
  30.    adist := xdist*xdist + ydist*ydist;
  31.    If adist >= 0 then
  32.       distance := sqrt(adist)
  33.    Else
  34.       distance := 0;
  35.   End; { Dist }
  36.  
  37. This is one I use in some wind calculations for an aircraft fitted with
  38. GPS and LORAN-C.
  39.  
  40. Note that all Latitude And Longitudes are in Degrees with minutes and
  41. seconds converted to decimal degrees.
  42.